package com.anyou.mall.pla.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.mall.pla.domain.Banner;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.pla.service.IBannerService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 轮播图管理Controller
 *
 * @author gaochaohao
 * @date 2022-03-18
 */
@Api(tags = "轮播图管理")
@RestController
@RequestMapping("/pla/banner")
public class BannerController extends BaseController
{
    @Autowired
    private IBannerService bannerService;

    /**
     * 查询轮播图管理列表
     */
    @ApiOperation("查询轮播图管理列表")
    @PreAuthorize("@ss.hasPermi('pla:banner:list')")
    @GetMapping("/list")
    public TableDataInfo<List<Banner>> list(Banner banner)
    {
        startPage();
        List<Banner> list = bannerService.selectBannerList(banner);
        return getDataTable(list);
    }

    /**
     * 导出轮播图管理列表
     */
    /*@ApiOperation("导出轮播图管理列表")
    @PreAuthorize("@ss.hasPermi('pla:banner:export')")
    @Log(title = "轮播图管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Banner banner)
    {
        List<Banner> list = bannerService.selectBannerList(banner);
        ExcelUtil<Banner> util = new ExcelUtil<Banner>(Banner.class);
        util.exportExcel(response, list, "轮播图管理数据");
    }*/

    /**
     * 获取轮播图管理详细信息
     */
    /*@ApiOperation("获取轮播图管理详细信息")
    @PreAuthorize("@ss.hasPermi('pla:banner:query')")
    @GetMapping(value = "/{bannerId}")
    public ApiResult<Banner> getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return ApiResult.success(bannerService.selectBannerByBannerId(bannerId));
    }*/

    /**
     * 新增轮播图管理
     */
    @ApiOperation("新增轮播图管理")
    @PreAuthorize("@ss.hasPermi('pla:banner:add')")
    @Log(title = "轮播图管理", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody Banner banner)
    {
        return ApiResult.success(bannerService.insertBanner(banner));
    }

    /**
     * 修改轮播图管理
     */
    @ApiOperation("修改轮播图管理")
    @PreAuthorize("@ss.hasPermi('pla:banner:edit')")
    @Log(title = "轮播图管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody Banner banner)
    {
        return ApiResult.success(bannerService.updateBanner(banner));
    }

    /**
     * 删除轮播图管理
     */
    @ApiOperation("删除轮播图管理")
    @PreAuthorize("@ss.hasPermi('pla:banner:remove')")
    @Log(title = "轮播图管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bannerIds}")
    public ApiResult remove(@PathVariable Long[] bannerIds)
    {
        return ApiResult.success(bannerService.deleteBannerByBannerIds(bannerIds));
    }

    /**
     * 修改轮播图状态
     */
    /*@ApiOperation("修改轮播图状态")
    @PreAuthorize("@ss.hasPermi('pla:banner:disable')")
    @Log(title = "轮播图管理", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/{bannerId}")
    public ApiResult updateBannerStatus(@PathVariable("bannerId") Long bannerId)
    {
        return bannerService.updateBannerStatus(bannerId);
    }*/
}
